/**
 * Created by Administrator on 2017/5/27.
 */

var DBFactory = require('../conn/DBFactory');
var async = require('async');
var paymentDao = module.exports;

paymentDao.expiredOrders = function (cb) {
    DBFactory.getConnection(function(error, connection){
        if(error) {
            cb(error);
            return;
        } else {
            var sql = 'delete from tao_vip_order where ' +
                ' (UNIX_TIMESTAMP( NOW()) - UNIX_TIMESTAMP(created_date) ) >= 172800 and type = 0 ';
            connection.query(sql, [], function(err, result){
                if(err){
                    cb(err);
                    connection.release();
                } else {
                    var rows = {};
                    rows.expiredOrders = result.affectedRows;
                    cb(null, rows);
                }
                connection.release();
                return;
            });
        }
    });
}

